﻿using Md.Api.Model;
using Md.Api.Model.Util.Upload.Request;
using Md.Api.Service.Util.Upload;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Md.Api.Controllers.Util;
/// <summary>
/// 文件上传 - 工具
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("md-api/util/upload")]
public class UploadController : ControllerBase
{
    /// <summary>
    /// 本地单文件上传服务
    /// </summary>
    public LocalSingleUploadService localSingleUploadService { get; set; }
    /// <summary>
    /// 本地单文件上传
    /// </summary>
    /// <param name="form">表单</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("localSingle"), HttpPost]
    public async Task<ResponseMessageModel> LocalSingleUpload([FromForm] IFormCollection form)
    {
        var model = new RequestLocalSingleUploadModel();

        model.Form = form;
        model.TimesTamp = form["TimesTamp"];
        model.Mac = form["Mac"];
        model.Ip = form["Ip"];
        model.Sign = form["Sign"];
        model.Version = form["Version"];
        model.Token = form["Token"];

        return await Task.Run(() => localSingleUploadService.Execute(model));
    }
}

